# -*- coding: utf-8 -*-

"""
Description: 网站请求方法
"""
import requests
import json
from utils.req import get_request, post_request
import re
import html

BASE_URL = "https://www.bioxcell.com.cn"
REQ_HEADERS = {
    "accept": "application/json, text/plain, */*",
    "accept-language": "zh-CN,zh;q=0.9",
    "cache-control": "no-cache",
    "content-type": "application/json;charset=UTF-8",
    "origin": "https://www.bioxcell.com.cn",
    "referer": "https://www.bioxcell.com.cn",
    "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36",
    "x-requested-with": "XMLHttpRequest",
}


def decode_unicode_escape(s):
    # 处理Unicode转义序列
    return s.encode("utf-8").decode("unicode_escape")


def req_product_list(page=1) -> list:
    """
    获取产品列表(体内应用抗体分类)
    :param page: 页码
    :return: 产品列表数据
    """

    url = f"{BASE_URL}/index/product/getProductList"
    data = {
        "name": "in-vivo-antibodies",
        "filter": [
            {
                "cate_name": "分类",
                "str_name": "category",
                "name_list": [{"name": "体内应用抗体"}],
            }
        ],
        "page": page,
        "q": "",
    }
    data = json.dumps(data, separators=(",", ":"))
    response = post_request(url=url, headers=REQ_HEADERS, data=data)
    return response.json()["data"]["list"]


def req_prodes(url: str) -> str:
    """请求商品详情信息

    Args:
        url (str): 商品详情 URL

    Returns:
        str: 商品详情HTML 文本
    """
    response = get_request(url=url, headers=REQ_HEADERS)
    # cleaned_content = clean_html_content(response.text)
    cleaned_content = json.loads(response.text)
    return cleaned_content
